package com.pearl.sharding.vertical.db.demo.controller;

import com.pearl.sharding.vertical.db.demo.entity.OrderEntity;
import com.pearl.sharding.vertical.db.demo.entity.UserEntity;
import com.pearl.sharding.vertical.db.demo.mapper.OrderMapper;
import com.pearl.sharding.vertical.db.demo.service.OrderService;
import com.pearl.sharding.vertical.db.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 自动代码生成
 * @since 2024-02-06
 */
@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/save")
    public Object save(){
        UserEntity user=new UserEntity();
        user.setUserName("测试");
        user.setPassword("123456");
        user.setLoginName("QBCD");
        user.setGender(1);
        user.setEmail("weew@qq.com");
        userService.save(user);
        return  "操作成功";
    }

    @GetMapping("/list")
    public Object list() {
        return userService.list();
    }


    private final OrderService orderService;

    private final OrderMapper orderMapper;

    @GetMapping("/userAndOrder")
    public Object userAndOrder(Long userId) {
        orderMapper.selectUserAndOrder();
        //
        UserEntity user = userService.getById(userId);
        OrderEntity order = orderService.getById(1754758746459979777L);
        log.info("user:"+user);
        log.info("order:"+order);
        return "查询成功";
    }
}
